package WorkflowService

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"seawolf-admin-go/internal/model/workflowEntity"
)

// 启动流程
// 获取流程定义 GetResourceByprocdefId()-> 启动流程实例 CreateProcInstTx()-> 生成执行流 GenerateExec() -> 生成新任务 NewTaskTx() -> 流程流转 MoveStage()

// 获取流程定义配置信息
func GetResourceByprocdefId(ctx context.Context, procdefId int64) (*workflowEntity.Node, int64, string, error) {
	procdef, err := GetProcdefById(ctx, procdefId)
	if err != nil {
		return nil, 0, "", err
	}
	if procdef == nil {
		return nil, 0, "", errors.New(fmt.Sprintf("流程【%d】不存在", procdefId))
	}
	node := &workflowEntity.Node{}
	err = json.Unmarshal([]byte(procdef.Resource), node)
	return node, procdef.Id, procdef.Name, err
}
